/*
 * @Author: xgq
 * @Date: 2020-05-14 09:38:04
 * @LastEditTime: 2020-05-22 18:44:23
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tuyibo\servers\api\wbms\recommend.js
 */

var express = require('express');
var reommend_router = express.Router();
var db = require('../../models');

 
reommend_router.post("/addRecommendCategory",async (req, res)=> {
    var from = req.body
    let result = await db.recommend_category.addRecommendCategory(from)
    res.json(result)
  })

  // 获取推荐类别
  reommend_router.get("/getRecommendCategory",async (req, res)=> {
    var [page = 1, pagesize = 30] = [req.query.pageNo, req.query.pageSize]
    let condition = {
      "pagesize": pagesize,
      "page": page
    }
    let categorys = await db.recommend_category.getRecommendCategory(condition)
    let data = {
      code: 200,
      rows: categorys
    }
    res.json(data)
  })

  // 修改状态
  reommend_router.post("/modifyCategoryStatus",async (req, res)=> {
    let pars = req.body
    let result = await db.recommend_category.modifyCategoryStatus(pars);
    res.json(result)
  })

  // 修改专题
  reommend_router.post("/editRecommendCategory",async (req, res)=> {
    let from = req.body
    let result = await db.recommend_category.editRecommendCategory(from);
    res.json(result)
  })


  reommend_router.post("/deleteRecommended",async (req, res)=> {
    var from = req.body
    let result = await db.recommend_category.deleteRecommended(from)
    res.json(result)
  })

  //拖动排序
  reommend_router.post("/recommendSort",async (req,res)=>{
    //start拖动的目的地
    //end从哪一行开始拖动的
    //start《end从后往前拖动   start》end从前往后拖动
    let result=await db.recommend_category.recommendSort(req.body.params)
    res.json(result)
  })


  //获取列表条数，用于添加排序
  reommend_router.get("/getRecommendCount",async (req,res)=>{
    let result = await db.recommend_category.getRecommendCount()
    res.json(result)
  })

  reommend_router.get("/fornt_getRecommend",async (req,res)=>{
    let categorys = await db.recommend_category.fornt_getRecommend()
    let data = {
      code: 200,
      rows: categorys
    }
    res.json(data)
  })

  // //通过id或name搜索专题
  // reommend_router.post("/getTopicByIdOrName",async (req,res)=>{
  //   let result=await db.recommend_category.getTagByIdOrName(req.body.queryString)
  //   res.json(result)
  // }
  

  module.exports = reommend_router